package com.yunkeji.api.index.controller;

import com.yunkeji.api.index.bo.RankingListBo;
import com.yunkeji.api.index.bo.SendHelloList;
import com.yunkeji.api.index.bo.UserListBo;
import com.yunkeji.api.index.service.IndexService;
import com.yunkeji.api.index.vo.*;
import com.yunkeji.common.annotation.RepeatSubmit;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.core.page.TableDataInfo;
import com.yunkeji.common.enums.app.AccountTypeEnums;
import com.yunkeji.config.annotation.ApiAuth;

import lombok.RequiredArgsConstructor;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.validation.Valid;

/**
 * 首页相关接口
 *
 * @author 老张
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/index")
public class IndexController extends BaseController {

    private final IndexService indexService;

    /**
     * 获取首页用户列表1=男神 2=女神 3=热门 4=新人
     *
     * @author 老张
     */
    @PostMapping("/userList")
    @ApiAuth(allow = {AccountTypeEnums.客服, AccountTypeEnums.用户})
    public TableDataInfo<UserListVo> userList(@Valid @RequestBody UserListBo bo) {
        // 现场沟通，分页200条
        bo.setPageSize(200);
        return indexService.queryUserList(bo);
    }

    /**
     * 获取一键打招呼列表-仅女号可用
     *
     * @author 老张
     */
    @PostMapping("/helloList")
    public R<List<RandomMatchListVo>> helloList() {
        return R.ok(indexService.helloList());
    }

    /**
     * 灵魂邂逅列表-每次刷新
     *
     * @author 老张
     */
    @PostMapping("/soulMatch")
    public R<List<RandomMatchListVo>> soulMatch() {
        return R.ok(indexService.soulMatch());
    }

    /**
     * 发送一键打招呼-女号可发送多个-男号只能发送一个,参考UI
     *
     * @author 老张
     */
    @PostMapping("/sendHelloList")
    @RepeatSubmit(interval = 3, timeUnit = TimeUnit.SECONDS, message = "打招呼过快,三秒后再试")
    public R sendHelloList(@Valid @RequestBody SendHelloList sendHelloList) {
        indexService.sendHelloList(sendHelloList);
        return R.ok();
    }

    /**
     * 视频速配 开始匹配 返回空说明匹配失败,返回ID走打视频的流程
     *
     * @author 老张
     */
    @PostMapping("/startMatch")
    public R<StartMatchVo> startMatch() {
        return R.ok(indexService.startMatch());
    }

    /**
     * 打招呼内容
     *
     * @author 老张
     */
    @PostMapping("/helloContent")
    public R<List<HelloContentVo>> helloContent() {
        List<HelloContentVo> data = indexService.helloContent();
        return R.ok(data);
    }

    /**
     * 排行榜
     *
     * @author 雷擎宇
     */
    @PostMapping("/rankingList")
    public TableDataInfo<RankingListVo> rankingList(@RequestBody @Valid RankingListBo bo){
        if(bo.getFlag().equals("1")){
            return indexService.getInviteRanking(bo);
        }
        return indexService.getWealthyRanking(bo);
    }
}
